{% extends "base.html" %}

{% block content %}
<div class="container mt-5">
    <h2 class="mb-4">{% if is_edit %}编辑{% else %}添加{% endif %}公司</h2>

    <!-- 消息闪现 -->
    {% with messages = get_flashed_messages(with_categories=true) %}
    {% if messages %}
    {% for category, message in messages %}
    <div class="alert alert-{{ 'danger' if category == 'error' else 'success' }}">
        {{ message }}
    </div>
    {% endfor %}
    {% endif %}
    {% endwith %}

    <form method="POST"
        action="{{ url_for('edit_company', company_id=company.id) if is_edit else url_for('add_company') }}">
        <div class="mb-3">
            <label for="name_cn" class="form-label">公司中文名</label>
            <input type="text" class="form-control" id="name_cn" name="name_cn" value="{{ company.name_cn if company }}"
                required>
        </div>

        <div class="mb-3">
            <label for="name_en" class="form-label">公司英文名</label>
            <input type="text" class="form-control" id="name_en" name="name_en" value="{{ company.name_en if company }}"
                required>
        </div>

        <div class="mb-3">
            <label for="address_cn" class="form-label">中文地址</label>
            <input type="text" class="form-control" id="address_cn" name="address_cn"
                value="{{ company.address_cn if company }}" required>
        </div>

        <div class="mb-3">
            <label for="address_en" class="form-label">英文地址</label>
            <input type="text" class="form-control" id="address_en" name="address_en"
                value="{{ company.address_en if company }}" required>
        </div>

        <div class="mb-3">
            <label for="website" class="form-label">公司网站</label>
            <input type="url" class="form-control" id="website" name="website" value="{{ company.website if company }}"
                required>
        </div>

        <button type="submit" class="btn btn-primary">提交</button>
        <a href="{{ url_for('list_companies') }}" class="btn btn-secondary">返回列表</a>
    </form>
</div>


{% endblock %}